<template>
  <a-spin :spinning="spinning != 0">
     <div>
      <a-row>
        <a-col :md="8">
          <a-row type="flex" align="middle" >
            <a-col :md="12" style="text-align: right;font-size: 36px;padding-right: 10px;color:#00baff;">
              <ych-icon type="icon-dingshirenwu"/>
            </a-col>
            <a-col :md="12" style="text-align: left;">
              <a-row>
                <a-col>{{$t('m.bpm.analyze.taskDueCount')}}</a-col>
              </a-row>
              <a-row>
                <a-col><span style="font-size: 24px;font-weight: bold;">{{taskDueCount}}</span></a-col>
              </a-row>
            </a-col>
          </a-row>
        </a-col>
        <a-col :md="8">
          <a-row type="flex" align="middle" >
            <a-col :md="12" style="text-align: right;font-size: 36px;padding-right: 10px;color:#00DB00;">
              <ych-icon type="icon-shijian"/>
            </a-col>
            <a-col :md="12" style="text-align: left;">
              <a-row>
                <a-col>{{$t('m.bpm.analyze.taskAvgDuetime')}}</a-col>
              </a-row>
              <a-row>
                <a-col><span style="font-size: 16px;font-weight: bold;">{{taskAvgDuetime}}</span></a-col>
              </a-row>
            </a-col>
          </a-row>
        </a-col>
        <a-col :md="8">
          <a-row type="flex" align="middle" >
            <a-col :md="12" style="text-align: right;font-size: 36px;padding-right: 10px;color:#ff0000;">
              <ych-icon type="icon-301"/>
            </a-col>
            <a-col :md="12" style="text-align: left;">
              <a-row>
                <a-col>{{$t('m.bpm.analyze.taskMaxDuetime')}}</a-col>
              </a-row>
              <a-row>
                <a-col><span style="font-size: 16px;font-weight: bold;">{{taskMaxDuetime}}</span></a-col>
              </a-row>
            </a-col>
          </a-row>
        </a-col>
      </a-row>
     </div>
  </a-spin>
</template>

<script>

  import YchConstant from "@/api/YchConstant";
  import {getAction} from '@/api/manage'

  export default {
    name:'TaskDueCount',
    props: {
      beginDate: {
        type: String,
        required: false
      },
      endDate: {
        type: String,
        required: false
      },
      groupIds:{
        type: String,
        required: false
      }
    },
    data () {
      return {
        show:true,
        spinning: 0,//遮罩
        data:[],
        taskDueCount:0,//任务超时数量
        taskAvgDuetime:0,//任务平均超时时长
        taskMaxDuetime:0,//任务最大超时时长
        url:{
          list:YchConstant.PREFIX_BPM + '/analyze/processAnalyzeRest/getTaskDueCount/v1',
        },
      }
    },
    methods: {
      queryData(){
        let that = this
        this.spinning++;
        let params = {
          beginDate:this.beginDate,
          endDate:this.endDate,
          groupIds:this.groupIds
        }
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.data = res.result
            if(this.data && this.data.length){
              this.data.forEach(item=>{
                if(item.name == 'tasDueCount'){
                  that.taskDueCount = item.count;
                }else if(item.name=='taskAvgDuetime'){
                  that.taskAvgDuetime = that.timeFormat(item.count);
                }else if(item.name == 'taskMaxDuetime'){
                  that.taskMaxDuetime = that.timeFormat(item.count);
                }
              })
            }
          } else {
            this.messageUtil.warning(res.message);
          }
        }).finally(() => {
          this.spinning--;
        });

      },
      timeFormat(t){
        if(t==null){
          return ''
        }
        let timeStr;
        let d = 24*60*60
        let h = 60*60
        let m = 60
        let s = 1
        let d1 = Math.floor(t/d)
        let h1 = Math.floor((t%d)/h)
        let m1 = Math.floor((t%h)/m)
        let s1 = Math.floor((t%m)/s)
        if(d1>0){
          timeStr = d1+this.$t('m.common.label.days')+h1+this.$t('m.common.label.hours')+m1+this.$t('m.common.label.minutes')+s1+this.$t('m.common.label.seconds')
        }else if(h1>0){
          timeStr = h1+this.$t('m.common.label.hours')+m1+this.$t('m.common.label.minutes')+s1+this.$t('m.common.label.seconds')
        }else if(m1>0){
          timeStr = m1+this.$t('m.common.label.minutes')+s1+this.$t('m.common.label.seconds')
        }else{
          timeStr = s1+this.$t('m.common.label.seconds')
        }
        return timeStr
      },
    },
    mounted () {
      this.queryData()
    },
  }
</script>
